package bishizhuanyong.用友;

import java.util.Scanner;
import java.util.Stack;

//岛屿问题
public class Main {
    public static int edge=1000;
    public static int m=0,n=0;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[][] grid=new int[edge][edge];
        int i=0;
        while (in.hasNextLine()){
            String s = in.nextLine();
            String[] split = s.split(",");
            n= split.length;
            for (int j=0;j< split.length;j++)
                grid[i][j]=Integer.valueOf(split[j]);
            i++;
        }
        m=i;
        int res=0;
        for (int k=0;k<m;k++){
            for (int j=0;j<n;j++){
                if (grid[k][j]==1) {
                    int tmp=process(grid, k, j);
                    res=Math.max(tmp,res);
                }
            }
        }
        System.out.println(res);
    }

    public static int process(int[][] gird,int x,int y){
        if (x<0||x>=m||y<0||y>=n)
            return 0;
        if (gird[x][y]!=1)
            return 0;
        gird[x][y]=-1;
        return process(gird,x+1,y)+
                process(gird,x-1,y)+
                process(gird,x,y+1)+
                process(gird,x,y-1)
                +1;
    }


    //单调栈
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 采用单调递减栈，栈顶元素最小，因为前面楼层低，不会挡住后面；前面高，才会挡住后面，栈顶是最接近当前位置的楼，所以要最小，代表此时栈顶所在位置向某一方向能看到其它楼的楼顶。
     * @param heights int整型一维数组 n座楼的楼层高度
     * @return int整型一维数组
     */
    public int[] findBuilding (int[] heights) {
        // write code here
        if (heights.length==1)
            return new int[]{1};
        int[] left=new int[heights.length];
        int[] right=new int[heights.length];
        Stack<Integer> stack1=new Stack<>();
        for (int i=0;i< heights.length;i++){
            left[i]=stack1.size();
            while (!stack1.isEmpty()&&heights[i]>stack1.peek())
                stack1.pop();
            stack1.push(heights[i]);
        }
        Stack<Integer> stack2=new Stack<>();
        for (int j= heights.length-1;j>=0;j--){
            right[j]=stack2.size();
            while (!stack2.isEmpty()&&heights[j]>stack2.peek())
                stack2.pop();
            stack2.push(heights[j]);
        }
        //help gc
        stack1=null;
        stack2=null;
        int[] res=new int[heights.length];
        for (int i=0;i<res.length;i++)
            res[i]= left[i]+ right[i]+1;
        return res;
    }

}
